import  random
from statistics import pstdev
from turtledemo.paint import switchupdown

ku = { "33344466":[1,"小明",123456,"XX省XX市XX县",5000,"中国农业银行"],"33344436":[1,"李鹏",123456,"中国河南省开元路104",20000,"中国农业银行"],
"13344466":[2,"赵浩",123456,"中国河南省王城大道109",10000,"中国农业银行"]}



def adduser(user,userType,name,password,address,money,bank_name):
    if len(ku)<=100:
        for e in ku.keys():
            if(user==e):
                return 2
        ku[user] = [userType, name, password, address, money, bank_name]
        return 1
    else: return 3

def save_money(user,money):
    count=0
    for e in ku.keys():
        if(user!=e):
            count+=1
    if count == len(ku):
        return False
    else:
        ku[user][4]+=money
        return True

def draw_money(user,password,money):
    count=0
    for e in ku.keys():
        if(user!=e):
            count+=1
    if count == len(ku):
        return 1
    else:
        if password!=ku[user][2]:
            return 2
        else:
            if ku[user][4] - money <= 0:
                return 3
            else:
                ku[user][4]-=money
                return 0

def trans_money(user1,user2,password,money):
    count1 = 0
    count2 = 0
    for e in ku.keys():
        if (user1 != e):
            count1 += 1
        if (user2 != e):
            count2+=1
    if count1 == len(ku)|count2==len(ku):
        return 1
    else:
        if password != ku[user1][2]:
            return 2
        else:
            if ku[user1][0] ==1:
                if money>50000:
                    return 4
            elif ku[user1[0]]==2:
                if money>20000:
                    return 5
            elif ku[user1][4]-money<0:
                return 3
            else:
                ku[user1][4]-=money
                ku[user2][4]+=money
                return 0

def query(user,password):
    count = 0
    for e in ku.keys():
        if (user != e):
            count += 1
    if count == len(ku):
        print("无该用户信息")
        return
    else:
        if password != ku[user][2]:
            print("密码错误")
            return
        else:
            print("当前账号：{}，密码：{}，余额{}，用户居住地址：{}，当前账户的开户行：{}".format(user,password,ku[user][4],ku[user][3],ku[user][5]))



def main():
    result=""
    print("*"*35)
    print("*        中国农业银行账户管理系统      *")
    print("*"*35)
    print("*               选项               *")
    print("*              1.开户              *")
    print("*              2.存钱              *")
    print("*              3.取钱              *")
    print("*              4.转账              *")
    print("*              5.查询              *")
    print("*              6.Bye              *")
    print("*"*35)
    try:
        key=int(input("请选择服务："))
    except:
        print("输入类型错误，请重启系统。")
    else:
        while key !=6:
            if key ==1:
                user = ""
                for i in range(0, 8):
                    user += str(random.randint(0, 10))
                userType = int(input("请选择账户类型(1/2)："))
                name = input("请输入姓名：")
                password = int(input("请输入密码："))
                address = input("请输入国家：")
                address += input("请输入省份(如河南省)：")
                address += input("请输入街道(如开元路)：")
                address += input("请输入门牌号：")
                money = int(input("初始存款："))
                bank_name= "中国农业银行"
                result=adduser(user,userType,name,password,address,money,bank_name)
                if result==1:
                    print("开户成功，你的账号为：{}".format(user))
                elif result==2:
                    print("已存在用户")
                elif result ==3:
                    print("用户库已满")
                else:
                    print("系统错误")
                key=int(input("请选择服务："))
            elif key ==2:
                user=input("请输入账号：")
                money=int(input("请输入存入的金额："))
                if save_money(user,money):
                    print("存入成功,余额为：{}".format(ku[user][4]))
                else:
                    print("存入失败")
                key=int(input("请选择服务："))
            elif key ==3:
                user = input("请输入账号：")
                password=int(input("请输入密码："))
                money = int(input("请输入取钱金额："))
                num=draw_money(user,password,money)
                if num==1:
                    print("用户不存在")
                elif num==2:
                    print("密码不正确")
                elif num==3:
                    print("余额不足")
                elif num==0:
                    print("取钱成功，余额为：{}".format(ku[user][4]))
                else:
                    print("系统错误")
                key = int(input("请选择服务："))
            elif key ==4:
                user1=input("请输入转出账号：")
                password = int(input("请输入转出账号的密码："))
                user2=input("请输入转入账号：")
                money=int(input("请输入转出的金额："))
                num=trans_money(user1,user2,password,money)
                if num==1:
                    print("用户不存在")
                elif num==2:
                    print("密码不正确")
                elif num==3:
                    print("余额不足")
                elif num==0:
                    print("转账成功")
                elif num==4 | num==5:
                    print("转账超出限制")
                else:
                    print("系统错误")
                key=int(input("请选择服务："))
            elif key ==5:
                user=input("请输入账号：")
                password =int(input("请输入密码："))
                query(user,password)
                key = int(input("请选择服务："))
            elif key ==6:
                return
            else: key=int(input("无效输入，请重新输入："))
main()